package com.xyyl.patient.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.xyyl.patient.core.controller.BaseController;
import com.xyyl.patient.core.support.Pager;
import com.xyyl.patient.core.util.ResponseBodyResult;
import com.xyyl.patient.entity.article.ArticleEntity;
import com.xyyl.patient.service.article.ArticleService;

/**
 * @Description: 文章管理
 * @author wqs
 *
 */
@RestController
@RequestMapping("/article")
public class ArticleController extends BaseController {

	@Autowired
	private ArticleService articleService;

	/**
	 * @param @return
	 *            参数
	 * @return JSONObject 返回类型
	 * @throws @Title:
	 *             queryArticleList
	 * @Description: 文章列表
	 */
	@RequestMapping(value = "/findArticle", method = RequestMethod.GET)
	public JSONObject queryArticleList() {
		Pager pager = super.initPage();

		try {
			List<ArticleEntity> articleList = articleService.queryList(pager);

			return ResponseBodyResult.success(articleList);
		} catch (Exception e) {
			return ResponseBodyResult.error("文章列表查询失败!", e);
		}
	}

	/**
	 * 文章详情页
	 * 
	 * @param articleId
	 * @return
	 */
	@RequestMapping(value = "/articleDetail", method = RequestMethod.GET)
	public JSONObject articleDetail(@RequestParam Integer articleId) {
		try {
			ArticleEntity articleEntity = articleService.getArticleById(articleId);
			return ResponseBodyResult.success(articleEntity);
		} catch (Exception e) {
			return ResponseBodyResult.error("文章详情查询失败!", e);

		}

	}

	/**
	 * 首页 每日导读
	 * 
	 * @param articleId
	 * @return
	 */
	@RequestMapping(value = "/articleIndex", method = RequestMethod.GET)
	public JSONObject articleIndex() {
				Pager pager = super.initPage();
				pager.setPageSize(3);
		try {
			List<ArticleEntity> articleList = articleService.queryList(pager);
			return ResponseBodyResult.success(articleList);
		} catch (Exception e) {
			return ResponseBodyResult.error("文章详情查询失败!", e);

		}

	}

	/**
	 * @param @return
	 *            参数
	 * @return JSONObject 返回类型
	 * @throws @Title:
	 *             queryArticleList
	 * @Description: 文章列表
	 */
	@RequestMapping(value = "/articleBanner", method = RequestMethod.GET)
	public JSONObject queryArticleBannerList() {

		try {
			List<ArticleEntity> articleList = articleService.queryArticleBannerList();

			return ResponseBodyResult.success(articleList);
		} catch (Exception e) {
			return ResponseBodyResult.error("文章列表查询失败!", e);
		}
	}
}
